/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#include "cardwidgetsizemgr.h"
#include <QVector>

using namespace client;

qreal CardWidgetSizeMgr::sm_cardRatio = 20.0 / 31.0;
qreal CardWidgetSizeMgr::sm_lifePointCardRatio[] = {0, 19 / 75, 31 / 75, 44 / 75, 57 / 75, 68 / 75};

int heightMinimal = 50;
int heightInitial = 75;
int heightMaximal = 150;

CardWidgetSizeMgr::CardWidgetSizeMgr():
        QObject(0),
        m_sizes(CSR_MAXVALUE + 1)
{
    m_sizes[CSR_Normal] = QSize(width(heightInitial), heightInitial);
    m_sizes[CSR_Zoomed] = QSize(200, 310);
}

int CardWidgetSizeMgr::lifeLevel(int lifePoints) const
{
    if (lifePoints < 0 || lifePoints > 5) {
        return 0;
    }
    return (int)(m_sizes[CSR_Normal].height() * sm_lifePointCardRatio[lifePoints]);
}

/* slot */
void CardWidgetSizeMgr::cardSizeUp()
{
    int height = m_sizes[CSR_Normal].height();
    height += 5;
    if (height > heightMaximal) {
        return;
    }
    m_sizes[CSR_Normal] = QSize(width(height), height);
    emit cardSizeChanged();
}

/* slot */
void CardWidgetSizeMgr::cardSizeDown()
{
    int height = m_sizes[CSR_Normal].height();
    height -= 5;
    if (height < heightMinimal) {
        return;
    }
    m_sizes[CSR_Normal] = QSize(width(height), height);
    emit cardSizeChanged();
}

int CardWidgetSizeMgr::width(int height)
{
    return (int)(height * sm_cardRatio);
}
